package Offer2017;

/**
 * 二维数组中的查找
 * Created by 雷文康 on 2017/12/27.
 */
public class Test03 {
    public static void main(String[] args)
    {
        int[][] matrix = {{0,3,6},{1,4,7},{2,5,8}};
        System.out.println(findNum(matrix, 3));
    }
    public static boolean findNum(int[][] matrix, int num){
        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
            return false;
        }
        int rows = matrix.length;
        int columns = matrix[0].length;
        int row = 0;
        int column = columns - 1;
        while (row <= rows - 1 && column >= 0){
            if (num == matrix[row][column]) {
                return true;
            } else if (num < matrix[row][column]) {
                column--;
            } else {
                row++;
            }
        }
        return false;
    }
}
